﻿namespace dogd
{
	/// <summary>
	/// Key represents a database field corresponding to a primary or foreign key.
	/// </summary>
	public class Key
	{
		/// <summary>
		/// Constant denoting an uninitialised key field.
		/// </summary>
		public const int InvalidValue = -1;

		/// <summary>
		/// Initialize default instance with an invalid key value.
		/// </summary>
		public Key()
		{
			this.Value = InvalidValue;
		}

		/// <summary>
		/// Initialize using an existing db key value.
		/// </summary>
		/// <param name="existingKey"></param>
		public Key(int existingKey)
		{
			this.Value = existingKey;
		}

		/// <summary>
		/// The key value.
		/// </summary>
		public int Value
		{
			get;
			set;
		}

		/// <summary>
		/// Whether this key is valid or not.
		/// </summary>
		public bool IsValid
		{
			get { return this.Value > InvalidValue; }
		}

		/// <summary>
		/// ToString override method.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return this.Value.ToString();
		}

		/// <summary>
		/// GetHashCode override.
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			return this.Value.GetHashCode();
		}
	}
}
